package com.mangowang.module.main.web.inteface;

import android.os.Handler;
import android.os.Message;
import android.webkit.JavascriptInterface;

import com.mangowang.lib.common.util.LogUtil;
import com.mangowang.module.main.web.ui.WebViewActivity;


public class JavaScriptInterface {

    private Handler handler;

    public JavaScriptInterface(Handler handler) {
        this.handler = handler;
    }

    @JavascriptInterface
    public void back() {
        Message message = new Message();
        message.what = WebViewActivity.BACK;
        handler.sendMessage(message);
    }


    @JavascriptInterface
    public void goLogin() {
        LogUtil.e("frank", "H5吊起登录");
        Message message = new Message();
        message.what = WebViewActivity.LOGIN;
        handler.sendMessage(message);
    }


    @JavascriptInterface
    public void goToCapture() {
        Message message = new Message();
        message.what = WebViewActivity.GOTOCAPTURE;
        message.obj = "goToCapture";
        handler.sendMessage(message);
    }


    @JavascriptInterface
    public void logout() { //
        Message message = new Message();
        message.what = WebViewActivity.LOGIN_OUT;
        handler.sendMessage(message);
    }

    @JavascriptInterface
    public void goToMain() {
        Message message = new Message();
        message.what = WebViewActivity.GOTOMAIN;
        handler.sendMessage(message);
    }


    @JavascriptInterface
    public void jumpTo(String url) {
        Message message = new Message();
        message.what = WebViewActivity.JUMPTO;
        message.obj = url;
        handler.sendMessage(message);
    }

    @JavascriptInterface
    public void uploadFile(String methodName) {
        Message message = new Message();
        message.what = WebViewActivity.TAKEPHOTO;
        message.obj = methodName;
        handler.sendMessage(message);
    }

    @JavascriptInterface
    public void saveShareImage(String imageUrl) {
        LogUtil.e("imageUrl",imageUrl);
        Message message = new Message();
        message.what = WebViewActivity.DOWNLOAD;
        message.obj = imageUrl;
        handler.sendMessage(message);
    }

    @JavascriptInterface
    public void saveImage(String imageString) {
        Message message = new Message();
        message.what = WebViewActivity.SAVE;
        message.obj = imageString;
        handler.sendMessage(message);
    }

}